﻿using PLC.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PLC.Manager
{
    public  class TestEnvManager : IEnvDataManager
    {
        int dn;
        double transformRadio;

        Double[,] datas = new Double[,]
        {
            #region
            /*{ 0.00  ,  -0.42 ,  819.78 , 4.91 ,   383.99 , 2.21*1000  ,  2974.77, 19.870001   },
            { 7.51  ,  -0.44  , 796.27 , 6.87 ,   387.45,  3.80*1000 ,   2958.50, 19.870001  },
            { 8.82  ,  -0.56  , 785.24,  7.23 ,   387.44,  4.06*1000 ,   2956.33, 19.870001  },
            { 11.33 ,  -0.53  , 756.67 , 7.85  ,  387.20,  4.51*1000 ,   2950.36 ,19.870001 },
            { 12.55 ,  -0.44  , 737.68 , 8.29  ,  387.25 , 4.82*1000 ,   2946.29 ,19.870001  },
            { 13.29 ,  -0.49  , 725.74 , 8.30 ,   387.33 , 4.84*1000 ,   2946.02, 19.870001 },
            { 14.26 ,  -0.53  , 710.55 , 8.51 ,   387.50,  4.97*1000 ,   2945.20, 19.870001 },
            { 16.34 ,  -0.62 ,  674.02 , 8.88 ,   387.58 , 5.23*1000 ,   2944.39 ,19.870001   },
            { 17.93 ,  -0.99  , 638.39 , 9.13  ,  387.30 , 5.40*1000 ,   2941.13 ,19.870001  },
            { 19.60 ,  -0.56  , 595.17 , 9.31  ,  387.50,  5.53*1000 ,   2938.15 ,19.870001 },
            { 22.14 ,  -0.92 ,  524.46 , 9.60 ,   387.45  ,5.73*1000 ,   2935.98, 19.870001  },*/

            /*{ 71.82 ,  0.26,    10.13,   17.15,   392.33,  6.32*1000 ,      563.16, 19.870001 },
            { 72.74,   1.31 ,   9.95  ,  17.17,   392.80,  6.29*1000,         563.16, 19.870001 },
            { 73.38 ,  1.51 ,   106.34 , 18.87,   391.94,  8.19*1000,     562.35, 19.870001 },
            { 71.53,   1.77 ,   201.65,  21.43,   392.94,  10.49*1000,      561.26, 19.870001 },
            { 71.02,   1.89 ,   297.50,  23.21,   391.41,  11.91*1000 ,    561.26, 19.870001 },
            { 70.32,   1.53,    414.14,  26.08,   391.51,  14.10*1000,     560.45, 19.870001 },
            { 69.93 ,  1.67,    508.55,  28.63 ,  390.55,  15.89*1000,      559.09, 19.870001 },
            { 69.22,   1.94 ,   610.00,  31.59,   390.10,  18.00*1000 ,    558.01, 19.870001 }

            { 0.00 ,   26.46,   647.80 , 52.49,   386.14,  19.22*1000 ,     1496.20  ,19.870001 },
            { 118.50,  18.15 ,  636.95 , 67.76  , 384.60 , 32.86*1000  ,    1493.22 ,19.870001 },
            { 224.98 , 4.67 ,   493.44,  87.54 ,  383.30 , 47.19*1000 ,     1487.93  ,19.870001},
            { 264.99 , -1.90 ,  403.74,  93.63,   380.93 , 51.39*1000  ,    1486.84   ,19.870001},
            { 300.00,  -11.54,  286.01 , 99.52  , 382.20 , 55.27*1000 ,     1485.76  ,19.870001},*/
            #endregion

            #region 恒力泵业的数据
            /*
{ 0.00,  34.88, 387.29 ,32.48, 379.16,  12.58*1000,  1495.39,19.870001 },
{ 30.04 ,30.68, 389.46, 33.17, 379.67,  12.65*1000,  1492.40,19.87},
{ 60.04, 25.90, 385.66, 37.35, 377.83,  16.67*1000,  1491.05,19.87 },
{ 89.61, 24.23, 381.86, 39.52, 378.08,  18.27*1000,  1491.59 ,19.87 },
{ 120.29,21.12, 371.01, 42.81, 378.96,  20.81*1000,  1491.05, 19.87},
{ 150.22,17.08, 353.74, 45.77, 379.33,  22.96*1000,  1489.15, 19.87},
{ 180.17,13.42, 333.12, 48.35, 379.92,  24.85*1000,  1488.47, 19.87 },
{ 200.11,11.29, 325.07, 48.93, 378.95,  25.14*1000,  1487.52 ,19.87 },
{ 219.93,8.07,  304.82, 50.47, 379.71,  26.27*1000,  1486.17 ,19.87 },
{ 240.01,2.81,  274.53, 52.70, 374.68,  27.88*1000,  1486.71 ,19.87 },
{ 259.90,-0.32, 257.08, 53.23, 376.71,  28.13*1000,  1483.18 ,19.87 },
{ 280.38,-7.28, 202.82, 55.05, 377.23,  29.34*1000,  1483.05, 19.87 },
{ 299.85,-10.19,173.34, 55.75, 379.33,  29.99*1000,  1484.13, 19.87},
{ 335.99,-23.21,73.51,  57.43, 377.42,  31.09*1000,  1481.82, 19.87 }*/
            #endregion

            #region 凯泉泵业,潜水泵测试
            /*{0.00,  -5.26,  428.8800,  5.68,  403.66,  3.360*1000, 2937.88, 28.83},
            {1.15,  -4.22,  414.5000,  5.70,  404.61,  3.380*1000, 2936.25, 28.83},
            {1.96,-4.55,400.5800,5.78,404.22,   3.440*1000, 2935.98,    28.78},
            {4.90,-6.51,361.4300,6.16,405.83,   3.720*1000, 2932.18,    28.76},
            {8.80,-18.00,326.3400,6.61,407.2,   4.070*1000, 2926.21,    28.71},
            {10.34,-20.75,306.1800,6.80,407.64, 4.200*1000, 2918.89,    28.67},
            {11.70,-29.23,289.0000,6.97,408.26, 4.340*1000, 2919.7,     28.69},
            {12.74,-32.87,276.1600,7.09,407.96, 4.420*1000, 2916.99,    28.67},
            {13.50,-36.23,264.8500,7.19,409.16, 4.500*1000, 2917.8,     28.67},
            {14.08,-38.76,254.8200,7.21,409.65, 4.520*1000, 2913.74,    28.67},
            {14.53,-40.83,248.3000,7.31,409.97, 4.590*1000, 2913.74,    28.67},
            {14.85,-42.37,242.2500,7.27,409.65, 4.570*1000, 2911.57,    28.67},
            {15.10,-43.40,239.4400,7.34,410.21, 4.620*1000, 2914.82,    28.65},
            {15.58,-45.55,234.1100,7.36,410.01, 4.640*1000, 2911.29,    28.67}*/
            #endregion

            #region 50-20-50II数据,潜水泵
            
             /*{ 0.000,-0.0414*1000, 0.5349375*1000,  9.46,380, 5.141*1000,2962.0,25.000},
             {3.480,-0.0329*1000, 0.522149816*1000, 9.92,380, 5.422*1000,2949.8,25.000 },
             {5.110,-0.0307*1000, 0.514637901*1000, 10.17,380,5.612*1000,2959.1,25.000 },
             {6.970,-0.0297*1000, 0.507201296*1000, 10.39,380,5.777*1000,2944.2,25.000 },
             {9.230,-0.0297*1000, 0.495527409*1000, 10.85,380,6.094*1000,2976.8,25.000 },
             {11.740,-0.0310*1000, 0.482553486*1000, 11.17,380,6.340*1000,2954.3,25.000 },
             {13.550,-0.0318*1000, 0.469883392*1000, 11.37,380,6.578*1000,2940.2,25.000 },
             {15.250,-0.0323*1000, 0.456532319*1000, 11.76,380,6.797*1000,2944.8,25.000 },
             {17.170,-0.0335*1000, 0.439930583*1000, 12.06,380,6.965*1000,2972.9,25.000 },
             {18.580,-0.0340*1000, 0.4117379*1000,12.51,380,7.281*1000,2882.6,25.000 },
             {22.070,-0.0368*1000, 0.397292499*1000, 12.64,380,7.457*1000,2947.0,25.000},
             {23.670,-0.0384*1000, 0.383233794*1000, 13.06,380,7.631*1000,2955.9,25.000 },*/

            #endregion
            #region 202508 自吸泵测试数据
            /*{ 0.50,  -19.74 ,278.33,     5.65, 401.56,  3.090*1000,  2965.28, 27.24 },
            { 53.01, -34.84 , 123.3400 , 8.41, 401.35, 5.170 * 1000, 2946.02, 27.22 },
            { 51.92, -33.78 , 128.0400 , 8.33, 402.86, 5.110 * 1000, 2946.56, 27.24 },
            { 46.05, -30.74 , 156.9800 , 7.97, 402.38, 4.850 * 1000, 2947.92, 27.24 },
            { 43.26, -29.41 , 165.1100 , 7.87, 402.32, 4.780 * 1000, 2945.75, 27.24 },
            { 34.46, -25.96 , 196.7600 , 7.33, 402.51, 4.390 * 1000, 2953.88, 27.22 },
            { 29.74, -24.33 , 213.0400 , 6.91, 402.95, 4.060 * 1000, 2954.16, 27.24 },
            { 18.94, -21.54 , 245.6800 , 6.26, 402.55, 3.570 * 1000, 2960.94, 27.24 },
            { 14.12, -20.74 , 255.9000 , 6.01, 403.33, 3.370 * 1000, 2965.82, 27.24 },
            { 1.68, -19.34 , 275.7900 , 5.63, 403.09, 3.070 * 1000, 2965.55, 27.27 }*/
#endregion

            #region 


            #endregion

            #region  数据，螺杆泵
            /**
             * 额定流量： 20
             * 额定总压：450
             * 泵效率：40
             * 额定转速:2900
             * 额定功率：7.5kw
             **/
            /*{ 0.00 , -6.00,   0.5720     , 9.46,  380, 6.55*1000, 2947.5, 25 },
            { 0.00 , -6.00,   0.5720*1000, 9.46,  380, 7*1000, 2947.5, 25 },
            { 3.48 , -6.50,   0.5449*1000, 9.92,  380, 7*1000, 2942.9, 25 },
            { 5.11 , -7.50,   0.5118*1000, 10.17, 380, 7*1000,  2934.4, 25 },
            {6.97,  -10.80,   0.4614*1000, 10.39, 380, 8*1000, 2926.9, 25 },
            {9.23,  -11.20,   0.4506*1000, 10.85, 380, 8*1000, 2926.1, 25 },
            {11.74, -15.20,   0.4013*1000, 11.17, 380, 8*1000, 2918.4, 25 },
            {13.55, -16.20,   0.3855*1000, 11.17, 380, 8*1000, 2916.5, 25 },
            {15.25, -16.20,   0.3855*1000, 11.17, 380, 8*1000, 2916.5, 25 },
            {17.17, -16.20,   0.3855*1000, 11.17, 380, 8*1000, 2916.5, 25 },
            {18.58, -16.20,   0.3855*1000, 11.17, 380, 8*1000, 2916.5, 25 },
            {20.24, -16.20,   0.3855*1000, 11.17, 380, 8*1000, 2916.5, 25 }*/


            #endregion

            #region  数据，螺杆泵
            /**
             * 额定流量： 250
             * 额定总压：1000
             * 泵效率：84
             * 额定转速:2900
             * 额定功率：90kw
             **/
            /*{248.00,0.00,1.1250*1000, 355.30,400,125*1000,2900,25},
            {250.00,0.00,1.0000*1000,355.66,400,119*1000,2900,25},
            {251.00,0.00,0.8750*1000,355.40,400,102*1000,2900,25},
            {252.50,0.00,0.7500*1000,355.56,400,95*1000,2900,25},
            {254.00,0.00,0.6250*1000,357.24,400,82*1000,2900,25},
            {255.00,0.00,0.5000*1000,357.63,400,78*1000,2900,25},
            {256.00,0.00,0.3750*1000,358.59,400,60*1000,2900,25},
            {257.50,0.00,0.2500*1000,359.17,400,50*1000,2900,25},
            {259.00,0.00,0.1250*1000,360.27,400,40*1000,2900,25},
            {260.00,0.00,0,         361.30,400,30*1000,2900,25}*/

            #endregion

            #region 数据
            /**
             * 额定流量： 15m3/h
             * 额定总压： 680kPa
             * 泵效率：   68%
             * 额定转速:  2900
             * 额定功率： 4.2kw
             * 入口直径： 50mm
             * 出口直径： 50mm
             * 入口取压高度：20mm
             * 出口取压高度：20mm
             **/
            /*{7.51,-0.44,796.27,6.87,387.45,3.80*1000, 2958.50,25},
            {8.82,-0.56,785.24,7.23,387.44,4.06*1000, 2956.33,25},
            {11.33,-0.53,756.67,7.85,387.20,4.51*1000, 2950.36,25},
            {12.55,-0.44,737.68,8.29,387.25,4.82*1000, 2946.29,25},
            {13.29,-0.49,725.74,8.30,387.33,4.84*1000, 2946.02,25},
            {14.26,-0.53,710.55,8.51,387.50,4.97*1000,2945.20,25},
            {16.34,-0.62,674.02,8.88,387.58,5.23*1000,2944.39,25},
            {17.93,-0.99,638.39,9.13,387.30,5.40*1000,2941.13,25},
            {19.60,-0.56,595.17,9.31,387.50,5.53*1000,2938.15,25},
            {22.14,-0.92,524.46,9.60,387.45,5.73*1000,2935.98,25},*/
            #endregion

            #region  数据，测试汽蚀的数据
            /**
             * 额定流量： 40
             * 泵效率：65
             * 额定汽蚀余量：3
             * 额定转速:2950
             * 额定功率：3kw
             * 进口直径：65mm
             * 出口直径：65mm
             * 临界汽蚀余量：3.09m
             * 额定效率：65
             * 额定扬程：17
             **/
            {41.16, 227.6, 0.3536*1000,0,0, 3.23*1000, 2950.17,  23.01 },
            {41.20, 114.2, 0.2405*1000,0,0, 3.23*1000, 2951.17,  23.01 },
            {41.09, 93.9,  0.2204*1000,0,0 ,3.22*1000, 2950.83,  23.01},
            {41.20, 78.7,  0.2054*1000,0,0, 3.22*1000, 2953.83,  23.01},
            {41.08, 53.7,  0.1794*1000,0,0, 3.22*1000, 2951.50,  23.01},
            {41.03, 52.9,  0.1781*1000,0,0 ,3.22*1000, 2949.33,  23.01},
            {41.24, 45,    0.1688*1000,0,0 ,3.23*1000, 2950.00,  23.01},
            {40.86, 32.8,  0.156* 1000,0,0 ,3.23*1000, 2949.17,  23.01},
            {40.74, 31.4,  0.1555*1000,0,0, 3.23*1000, 2949.83,  23.02},
            {40.68, 30.5,  0.1549*1000,0,0, 3.24*1000, 2953.17,  23.04},
            {40.54, 29.5,  0.1539*1000,0,0, 3.23*1000, 2949.83,  23.07},
            {40.46, 28.5,  0.1529*1000,0,0, 3.23*1000, 2951.33,  23.07},
            {40.27, 27.6,  0.1527*1000,0,0, 3.22*1000, 2949.50,  23.07},
            {39.98, 26.2,  0.1508*1000,0,0, 3.22*1000, 2949.83,  23.07},
            {39.62, 24.3,  0.146*1000, 0,0, 3.19*1000, 2950.67,  23.11}

            #endregion


            #region 汽蚀余量测试
            /*{ 0,          214.9887,  610.7177,    0, 0, 9093.602639 ,1491.8, 19.953888 },
            { 19.288786,   212.1798, 610.4049,    0, 0, 10063.07084, 1490,  19.953888 }, 
            { 38.676591,  209.9166,  606.8471,    0, 0, 11147.37142, 1489,  19.973078 }, 
            { 57.597595,  206.5657,  601.999,     0, 0, 12388.9817, 1488,  19.997065 }, 
            { 77.194753,  201.8744,  600.1321,    0, 0, 14180.91934, 1486.1, 19.98747 },
            { 102.62602,  210.1363,  609.0561,    0, 0, 16091.73222 ,1484,  20.001862 },
            { 119.92598,   209.2281, 604.1298,    0, 0, 17523.75764, 1483,  20.001862 },
            { 137.251454,  208.0708, 596.5156,    0, 0, 18840.53746, 1481,  20.001862 },
            { 159.629132, 206.5693,  588.0805,    0, 0, 20447.2631, 1479.6, 20.001862 },
            { 181.649586, 204.5075,  575.0415,    0, 0, 22344.78159, 1478,  20.001862 },
            { 196.933768, 202.5922,  560.7222,    0, 0, 23735.3054, 1476.9, 20.001862 },
            { 224.2871,    199.505,  537.1857,    0, 0, 25441.2661, 1474.7, 20.001862 },
            { 240.362285, 197.6226,  521.84,      0, 0, 26280.98611, 1473.8, 20.045011 },
            { 255.723016,  195.7769, 506.5042,    0, 0, 26995.20591, 1473,  20.049805 },
            { 273.303653, 193.3085,  487.4345,    0, 0, 27805.93764, 1472,  20.049805 },
            { 292.338712, 190.441,   457.6033,    0, 0, 28703.28647, 1471,  20.049805 },
            { 311.067584, 187.4234,  426.3842,    0, 0, 29438.10783, 1470,  20.097778 },
            { 332.194962, 183.9992,  392.2914,    0, 0, 30192.09458, 1469,  20.097778 },
            { 350.132834, 180.7509,  360.4663,    0, 0, 30668.27026, 1468,  20.097778 },
            { 368.912732, 177.5062,  318.7399,    0, 0, 31099.56362, 1467.6, 20.161743 }*/

            #endregion

        };


        public void Close()
        {
            
        }

        public void Init()
        {
   
        }

        public int Open()
        {
            return 0;
        }

        int index = 0;
        private int phaseAddress;

        public int PhaseAddress { get => phaseAddress; set => phaseAddress =value; }

        public EnvData ReadData(DynamicParams dynamicParams)
        {
            EnvData data = new EnvData();
            Random r = new Random();
            double[] number = new double[8];
            
                  for (int i = 0; i < 8; i++)
            {
                number[i] = 1.0;
                //number[i] = r.Next(95, 105)*0.01;
                //Console.WriteLine(number[i]);
            }
            data.Flow = datas[index, 0] * number[0];
            data.PresureIn = datas[index, 1] * number[1];
            data.PresureOut = datas[index, 2] * number[2];
            data.Current = datas[index, 3] * number[3];
            data.Voltage = datas[index, 4] * number[4];
            data.ShaftPower = datas[index, 5] * number[5];
            data.Speed = datas[index, 6] * number[6];
            data.Temperature = datas[index, 7] * number[7];
            //index++;
            if (index >= datas.Length)
            { index = 0; }
            

            return data;
        }

        public void FetchData()
        {
            index++;
        }
    }
}
